package com.bulkmail.sender.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class AttachmentListener implements ActionListener {

	private JTextField attachmentTextField;

	public AttachmentListener(JTextField attachmentJTextField) {
		this.attachmentTextField = attachmentJTextField;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		JFileChooser fileChooser = new AttachmentChooser();
		JFrame frame = new JFrame();
		frame.getContentPane().add(fileChooser);
		int result = fileChooser.showOpenDialog(null);
		switch (result) {
		case JFileChooser.APPROVE_OPTION:
			attachmentTextField
					.setText(fileChooser.getSelectedFile().getPath());
			break;
		case JFileChooser.CANCEL_OPTION:
			System.out.println("Cancel or the close-dialog icon was clicked");
			break;
		case JFileChooser.ERROR_OPTION:
			System.out.println("Error");
			break;
		}
		frame.setVisible(true);
		frame.pack();
	}
}
